/*
 * @Project Name: spring-boot
 * @File Name: UserService
 * @Package Name: com.hhly.spring.boot.cache
 * @Date: 2017/12/13 17:52
 * @Creator: linshixing-1199
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.service.star.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.dao.mapper.star.StarCategoryMapper;
import com.sm.shoplook.domain.star.StarCategory;
import com.sm.shoplook.service.star.StarCategoryService;
import com.sm.shoplook.vo.base.ApiException;
import com.sm.shoplook.vo.base.ApiResult;
import com.sm.shoplook.vo.base.BaseSearchVo;

/**
 * @author chenpy-1072
 * @desc 基础素材管理
 * @date 2017/12/13 17:52
 * @see
 */
@Service
public class StarCategoryServiceImpl implements StarCategoryService {

	private static final Logger LOGGER = LoggerFactory.getLogger(StarCategoryServiceImpl.class);
	@Autowired
	private StarCategoryMapper starCategoryMapper;

	@Override
	public ApiResult<PageInfo<StarCategory>> selectStarCategorysPage(BaseSearchVo baseSearchVo) {
		PageHelper.startPage(baseSearchVo.getOffset(), baseSearchVo.getPageSize());
		StarCategory starCategory = new StarCategory();
		starCategory.setStatus(1);
		List<StarCategory> materialCategories = starCategoryMapper.select(starCategory);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, new PageInfo<>(materialCategories));
	}

	@Override
	public ApiResult batchDelete(String[] idList) throws ApiException {
		int i = starCategoryMapper.batchDelete(idList);
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult saveStarCategory(StarCategory starCategory) throws ApiException {
		int i;
		if (starCategory.getId() == null) {
			i = starCategoryMapper.insertSelective(starCategory);
		} else {
			i = starCategoryMapper.updateByPrimaryKeySelective(starCategory);
		}
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult<List<StarCategory>> selectAllStarCategorys() {
		StarCategory starCategory = new StarCategory();
		starCategory.setStatus(1);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, starCategoryMapper.select(starCategory));
	}

	@Override
	public ApiResult<StarCategory> selectStarCategoryById(Integer id) {
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, starCategoryMapper.selectByPrimaryKey(id));
	}
}
